﻿using Quartz;

namespace AutoMail.Quartz
{
    /// <summary>
    /// 任务监听器
    /// </summary>
    public class JobListener : IJobListener
    {
        public string Name { get; } = nameof(JobListener);

        //任务被否决执行
        public Task JobExecutionVetoed(IJobExecutionContext context, CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                Console.WriteLine(context.JobDetail.Key + "任务被否决");
            });
        }

        //任务执行前
        public Task JobToBeExecuted(IJobExecutionContext context, CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                Console.WriteLine(context.JobDetail.Key+"任务执行前");
            });
        }

        //任务执行后
        public Task JobWasExecuted(IJobExecutionContext context, JobExecutionException? jobException, CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                Console.WriteLine(context.JobDetail.Key + "任务执行后");
            });
        }
    }
}
